package com.taotao.protobuf;

import com.google.protobuf.InvalidProtocolBufferException;

/**
 * @Description: ProtoBuf 测试类
 * @Author: TaoJF
 * @Date: Created in 2018/6/30 下午7:15
 */
public class ProtoBufTest {

    public static void main(String[] args) throws InvalidProtocolBufferException {
        //message设置属性值；
        DataInfo.Student student = DataInfo.Student.newBuilder().
                setName("Chris").setAge(28).setAddress("安徽").
                build();

        //转换成byte[]字节数组，传输；
        byte[] student2ByteArray = student.toByteArray();
        //将byte[]字节数组解析成对象；
        DataInfo.Student student1 = DataInfo.Student.parseFrom(student2ByteArray);

        //显示解析后对象的属性值；
        System.out.println(student.toString());
        System.out.println(student1.toString());
        System.out.println(student1.getName());
        System.out.println(student1.getAge());
        System.out.println(student1.getAddress());
    }

}
